#include "Test.h"

typedef ITest*(*InitCallback)();
typedef void(*KillCallback)(ITest*);

Test::Test(Module* module)
{
	mod = module;
	test = NULL;
	if (mod)
	{
		InitCallback init = (InitCallback)mod->GetFunc("CreateTest");
		if (init != NULL)
		{
			test = init();
		}
	}
}

Test::~Test()
{
	KillCallback kill = (KillCallback)mod->GetFunc("DestroyTest");
	if (kill != NULL)
	{
		kill(test);
	}
	if (mod != NULL)
	{
		delete mod;
	}
}

bool Test::Run()
{
	if (!test)
	{
		fprintf(stderr, "Test.Run: test is NULL\n");
		return false;
	}
	return test->Run();
}

TestInfo* Test::GetTestInfo()
{
	if (!test)
	{
		fprintf(stderr, "Test.GetTestInfo: test is NULL\n");
		return NULL;
	}
	return test->GetTestInfo();
}